<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>宿舍管理</title>
    <link type="text/css" href="css/base.css" rel="stylesheet"/>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/menu.js"></script>
    <script src='<%=basePath%>dwr/util.js' type="text/javascript"></script>
    <script src='<%=basePath%>dwr/engine.js' type="text/javascript"></script>
    <script src='<%=basePath%>dwr/interface/studentService.js' type="text/javascript"></script>
    <script src='<%=basePath%>dwr/interface/applicationService.js' type="text/javascript"></script>

    <script type="text/javascript" src="<%=basePath%>/js/jquery.min.js"></script>
    <link href='<%=basePath%>/css/bootstrap-2.3.2.css' rel='stylesheet'>
    <script type="text/javascript" src="<%=basePath%>/js/bootstrap.min.js"></script>
    <!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
    <script type="text/javascript">
        $(document).ready(function () {
            studentService.findStudents('${person.dormitory.id}', getResult);
        });

        function findStu(dormitory, campus, sex) {
            if (dormitory.toUpperCase() == '${person.dormitory.dormitoryId}'.replace("-", "")) {
                alert("不能与本宿舍交换哟~");
                $(".dormitoryNum").val("");
            } else
                studentService.findStudents(dormitory, campus, sex, getResults);
        }

        function getResult(student) {
            var select_list = '<option value="" style="text-align: center">' + '---------请选择---------' + '</option>';
            for (var i = 0; i < student.length; i++) {
                select_list += '<option style="text-align: center" value="' + student[i].studentId + '">'
                        + student[i].studentName + "</option>";
            }
            $("#apply").html(select_list);
        }

        function getResults(student) {
            if (student[0].studentId == '1111111') {
                alert("异性宿舍哟，学校不允许这样更换哟~");
                $(".dormitoryNum").val("");
            } else {
                var select_list = '<option value="" style="text-align: center">' + '---------请选择---------' + '</option>';
                for (var i = 0; i < student.length; i++) {
                    select_list += '<option style="text-align: center" value="' + student[i].studentId + '">'
                            + student[i].studentName + "</option>";
                }
                $("#exchange").html(select_list);
            }
        }

        function check(stuId) {
            applicationService.checkApply(stuId, getCheck);
        }

        function getCheck(b) {
            if (!b) {
                alert("该学生已经提交申请！请勿重复提交！");
                $("#apply").val("");
            }
        }

    </script>
</head>

<body>
<%@ include file="/page/share/menu.jsp" %>

<div id="content">
    <form method="post" action="Application.action">
        <table style="width: 860px;margin-left: 20px;">
            <tr>
                <th colspan="6" style="text-align: center">
                    更换宿舍申请表
                </th>
            </tr>

            <tr>
                <td>
                    互换学生:
                </td>
                <td>
                    <label>
                        <select name="applyStu" style="height: 23px;margin: 2px auto;width: 150px;  " id="apply"
                                onchange="check(this.value)" >
                        </select>
                    </label>
                </td>
                <td align="center">
                    <span class="glyphicon glyphicon-resize-horizontal"></span>
                </td>
                <td align="center">
                    宿舍编号:<input type="text" name="dormitory"
                                onchange="findStu(this.value,'${person.dormitory.campus.campusName}','${person.dormitory.sex}')"
                                style="width: 60px" class="dormitoryNum"/>
                </td>
                <td align="center">
                    <span class="glyphicon glyphicon-circle-arrow-right"></span>
                </td>
                <td align="center">
                    <label>
                        <select name="exchangeStu" style="height: 23px;margin: 2px auto;  width: 150px;" id="exchange">
                        </select>
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    申请原因：
                </td>
                <td colspan="5">
                    <textarea rows="3" cols="67" name="reMarks"></textarea>
                </td>
            </tr>
            <tr>
                <td></td>
            </tr>
            <tr>
                <td colspan="2" align="right">
                    <input name="jiao" type="submit" class="btn btn-primary" value="提交申请"/>
                </td>
                <td colspan="2" align="right">
                    <input name="c" type="reset" class="btn btn-primary" value="重填申请"/>
                </td>
            </tr>
        </table>
    </form>
</div>


<div id="footer">
    <p style="text-align: center;color: #757575;padding: 20px 0px 0px 0px; font:12px;">Copyright © 2010-2013 蓝天白云团队
        版权所有</p>
</div>
</body>
</html>